﻿<Window x:Class="Caffeine.ChangeRecognitionPOC.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Caffeine.ChangeRecognitionPOC"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        ScrollViewer.CanContentScroll="True"
        Title="Caffeine Model - Change Recognition POC" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <TabControl ItemsSource="{Binding}"  VirtualizingStackPanel.VirtualizationMode="Recycling" SnapsToDevicePixels="True" IsSynchronizedWithCurrentItem="True">
        <TabControl.Resources>
            <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />
            <ObjectDataProvider x:Key="dataFromEnum" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="local:ViewModel.FormValue"/>
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
            <DataTemplate DataType="{x:Type local:ViewModel.FormViewModel}">
                <Border CornerRadius="5" BorderThickness="1" BorderBrush="White" Padding="5">
                    <Border.Style>
                        <Style TargetType="Border">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding AlternatingIndex.Value}" Value="0">
                                    <Setter Property="Background" Value="#CCCCCC" />
                                </DataTrigger>
                                <DataTrigger Binding="{Binding AlternatingIndex.Value}" Value="1">
                                    <Setter Property="Background" Value="#9999CC" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Grid Margin="0,0,0,0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel>
                            <WrapPanel Margin="0, 5, 0, 10">
                                <TextBlock Text="{Binding Name.Value}" FontWeight="Bold" />
                                <ComboBox Margin="10, 0" SelectedItem="{Binding Value.Value}" ItemsSource="{Binding Source={StaticResource dataFromEnum}}" />
                                <Button Command="{Binding CommitGraphCommand}" Content="Commit" Margin="10, 0, 0, 0" />
                                <Button Command="{Binding ResetGraphCommand}" Content="Reset" Margin="10, 0" />
                                <TextBlock FontWeight="Bold" Foreground="Red" Margin="10, 0" Visibility="{Binding Path=IsDirty, Converter={StaticResource booleanToVisibilityConverter}}"> Is Dirty</TextBlock>
                                <TextBlock FontWeight="Bold" Foreground="Red" Opacity=".6" Margin="10, 0" Visibility="{Binding Path=IsDirtyWithin, Converter={StaticResource booleanToVisibilityConverter}}"> Is Dirty Within</TextBlock>
                                <TextBlock FontWeight="Bold" Foreground="Purple" Margin="10, 0" Visibility="{Binding Path=IsInvalid, Converter={StaticResource booleanToVisibilityConverter}}"> Is Invalid</TextBlock>
                                <TextBlock FontWeight="Bold" Foreground="Purple" Opacity=".6" Margin="10, 0" Visibility="{Binding Path=IsInvalidWithin, Converter={StaticResource booleanToVisibilityConverter}}"> Is Invalid Within</TextBlock>
                            </WrapPanel>
                        </StackPanel>
                        <ListBox Grid.Row="1" ItemsSource="{Binding ChildViewModels}" HorizontalAlignment="Stretch" Margin="10,0,0,10">
                            <ListBox.Template>
                                <ControlTemplate>
                                    <StackPanel IsItemsHost="True" />
                                </ControlTemplate>
                            </ListBox.Template>
                            <ListBox.ItemContainerStyle>
                                <Style TargetType="ListBoxItem">
                                    <Setter Property="Margin" Value="5" />
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ListBoxItem">
                                                <ContentPresenter HorizontalAlignment="Stretch" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}" />
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.ItemContainerStyle>
                        </ListBox>
                    </Grid>
                </Border>
            </DataTemplate>
        </TabControl.Resources>
        <TabControl.ItemTemplate>
            <DataTemplate DataType="{x:Type local:ViewModel.FormViewModel}">
                <WrapPanel>
                    <TextBlock Text="{Binding Name.Value}" />
                    <TextBlock Foreground="Red" Text="*">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsDirty}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding IsDirtyWithin}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                </WrapPanel>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.Template>
            <ControlTemplate TargetType="TabControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib">
                <Grid
        ClipToBounds="True"
        SnapsToDevicePixels="True"
        KeyboardNavigation.TabNavigation="Local">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition
                Name="ColumnDefinition0" />
                        <ColumnDefinition
                Width="0"
                Name="ColumnDefinition1" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition
                Height="Auto"
                Name="RowDefinition0" />
                        <RowDefinition
                Height="*"
                Name="RowDefinition1" />
                    </Grid.RowDefinitions>
                    <TabPanel
            IsItemsHost="True"
            Name="HeaderPanel"
            Margin="2,2,2,0"
            Panel.ZIndex="1"
            KeyboardNavigation.TabIndex="1"
            Grid.Column="0"
            Grid.Row="0" />
                    <Border
                        BorderThickness="{TemplateBinding Border.BorderThickness}"
                        BorderBrush="{TemplateBinding Border.BorderBrush}"
                        Background="{TemplateBinding Panel.Background}"
                        Name="ContentPanel"
                        KeyboardNavigation.TabIndex="2"
                        KeyboardNavigation.TabNavigation="Local"
                        KeyboardNavigation.DirectionalNavigation="Contained"
                        Grid.Column="0"
                        Grid.Row="1">
                        <ScrollViewer>
                            <ContentPresenter Content="{TemplateBinding TabControl.SelectedContent}"
                                            ContentTemplate="{TemplateBinding TabControl.SelectedContentTemplate}"
                                            ContentStringFormat="{TemplateBinding TabControl.SelectedContentStringFormat}"
                                            ContentSource="SelectedContent"
                                            Name="PART_SelectedContentHost"
                                            Margin="{TemplateBinding Control.Padding}"
                                            SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger
            Property="TabControl.TabStripPlacement">
                        <Setter
                Property="Grid.Row"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <s:Int32>1</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Row"
                TargetName="ContentPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition0">
                            <Setter.Value>
                                <GridLength>*</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition1">
                            <Setter.Value>
                                <GridLength>Auto</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="FrameworkElement.Margin"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <Thickness>2,0,2,2</Thickness>
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <x:Static
                    Member="Dock.Bottom" />
                        </Trigger.Value>
                    </Trigger>
                    <Trigger
            Property="TabControl.TabStripPlacement">
                        <Setter
                Property="Grid.Row"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Row"
                TargetName="ContentPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Column"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Column"
                TargetName="ContentPanel">
                            <Setter.Value>
                                <s:Int32>1</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="ColumnDefinition.Width"
                TargetName="ColumnDefinition0">
                            <Setter.Value>
                                <GridLength>Auto</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="ColumnDefinition.Width"
                TargetName="ColumnDefinition1">
                            <Setter.Value>
                                <GridLength>*</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition0">
                            <Setter.Value>
                                <GridLength>*</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition1">
                            <Setter.Value>
                                <GridLength>0</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="FrameworkElement.Margin"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <Thickness>2,2,0,2</Thickness>
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <x:Static
                    Member="Dock.Left" />
                        </Trigger.Value>
                    </Trigger>
                    <Trigger
            Property="TabControl.TabStripPlacement">
                        <Setter
                Property="Grid.Row"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Row"
                TargetName="ContentPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Column"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <s:Int32>1</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="Grid.Column"
                TargetName="ContentPanel">
                            <Setter.Value>
                                <s:Int32>0</s:Int32>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="ColumnDefinition.Width"
                TargetName="ColumnDefinition0">
                            <Setter.Value>
                                <GridLength>*</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="ColumnDefinition.Width"
                TargetName="ColumnDefinition1">
                            <Setter.Value>
                                <GridLength>Auto</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition0">
                            <Setter.Value>
                                <GridLength>*</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="RowDefinition.Height"
                TargetName="RowDefinition1">
                            <Setter.Value>
                                <GridLength>0</GridLength>
                            </Setter.Value>
                        </Setter>
                        <Setter
                Property="FrameworkElement.Margin"
                TargetName="HeaderPanel">
                            <Setter.Value>
                                <Thickness>0,2,2,2</Thickness>
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <x:Static
                    Member="Dock.Right" />
                        </Trigger.Value>
                    </Trigger>
                    <Trigger
            Property="UIElement.IsEnabled">
                        <Setter
                Property="TextElement.Foreground">
                            <Setter.Value>
                                <DynamicResource
                        ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <s:Boolean>False</s:Boolean>
                        </Trigger.Value>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </TabControl.Template>
    </TabControl>
</Window>
